<?php
class page_base {

	private $titre;
	private $style=array('base', 'modele');
	private $corps;
	private $page;
	public $var;
	public $pseudo;
	
	public function __construct($p){
		$this->page = $p;
		session_start();
	}

	/******** Gestion des setters  *******************/
	public function __set($propriete, $valeur) {
		switch ($propriete) {	
			case 'style' : {
				$this->style[count($this->style)+1] = $valeur;
				break;
			}
			
			case 'corps' : {
				$this->corps = $valeur;
				break;
			}
			
			case 'titre' : {
					$this->titre = $valeur;
					break;
			}
		}
	}
	/******** Gestion du titre  *******************/
	private function affiche_titre() {
		echo $this->titre;
	}
	
	public function session ()
	{
		$_SESSION['id']="";
		if (isset($_POST['deconnexion']))
		{
			$_SESSION = array();
			session_destroy();
			

		}
		if (isset($_COOKIE['pseudo'])&&(!empty($_COOKIE['pseudo'])))
		{
			$_SESSION['id'] = $_COOKIE['pseudo'];
		}
		if (isset($_POST['pseudo'])&&(!empty($_POST['pseudo'])))
		{
			$_SESSION['nom'] = $_POST['pseudo'];
		 	setcookie('pseudo', $_SESSION['nom'], time() + 365*24*3600, null, null, false, true);
		}
	}
	
	public function getvar()
	{
		
		if (isset($_GET['var']))
		{
		   $this->var = $_GET['var'];
		}
	}
	
	/*************Gestion des styles *********************/
	private function affiche_style() {
		foreach ($this->style as $s) {
			echo "<link rel='stylesheet' href='STYLE/".$s.".css' />\n";
		}
		echo " <script src=\"//code.jquery.com/jquery-1.10.2.js\"></script>";
	}
	/*************Gestion En-t�te *********************/
	protected function affiche_entete() {
 	

	}
	
	/*************Gestion Menu *********************/
	private function affiche_menu() {
		/*
		?>
            <nav>
                  <ul>
				 <li><a href=""></a></li>
				</ul>
            </nav>
	<?php */
	
		}
		
		/*************Gestion Corps *********************/
		protected function affiche_corps() 
				{
					echo $this->corps;
				}
		private function donne()
		{
			
		}

	/************** Affichage du pied de la page ***************************/
	private function affiche_footer() {
		
		/* echo "<footer>
<p>Site de travail Slam4 2014-2015 - servant de base � l'apprentissage du PHP </p>	
			</footer>";*/
		
	}
	
	/******************** Fonction permettant l'affichage de la page **************/
	public function affiche() {
	$this->session();
		?>
			<!DOCTYPE html>
			<html lang='fr'>
				<head>
					<title>
						<?php $this->affiche_titre(); ?>
					</title>
					<meta charset="utf8_encode" />
					<meta name="viewport" content="initial-scale=1.0; maximum-scale=1.0; width=device-width;">
						<?php 
						$this->affiche_style(); 
					?>
				</head>
				<body>
					
					<div id="global">
					<?php
					$this->affiche_entete();
					?>
					<div id="centre">
					<?php
					$this->affiche_menu();
					?>
					<section>
					
					<?php $this->affiche_corps(); ?>
					</section>
					</div>
				
					</div>
				<?php 
					$this->affiche_footer();
				?>
			</html>
<?php
	}
}
?>

